package com.okq.util.page;

import java.util.List;

@SuppressWarnings("all")
public class Page<T> extends QueryParameter {
	private List<T> result = null;
	private int iDisplayStart;
	private int iDisplayLength;
	private int startPageNum;
	private int totalCount = -1;

	public int getStartPageNum() {
		this.startPageNum = (this.getPageNo() - 1) * this.iDisplayLength + 1;
		return this.startPageNum;
	}

	public void setStartPageNum(int var1) {
		this.startPageNum = var1;
	}

	public int getiDisplayStart() {
		return this.iDisplayStart;
	}

	public void setiDisplayStart(int var1) {
		this.iDisplayStart = var1;
		this.getPageNo();
	}

	public int getiDisplayLength() {
		return this.iDisplayLength;
	}

	public void setiDisplayLength(int var1) {
		this.iDisplayLength = var1;
		this.getPageNo();
	}

	public int getPageNo() {
		if (this.iDisplayStart > 0 && this.iDisplayLength > 0) {
			this.pageNo = (int) Math.ceil((double) (this.iDisplayStart / this.iDisplayLength)) + 1;
		}

		return this.pageNo;
	}

	public void setPageNo(int var1) {
		this.pageNo = var1;
	}

	public Page() {
	}

	public Page(int var1) {
		this.pageSize = var1;
	}

	public Page(int var1, boolean var2) {
		this.pageSize = var1;
		this.autoCount = var2;
	}

	public String getInverseOrder() {
		return this.order.endsWith("desc") ? "asc" : "desc";
	}

	public List<T> getResult() {
		return this.result;
	}

	public void setResult(List<T> var1) {
		this.result = var1;
	}

	public int getTotalCount() {
		if (this.totalCount < 0) {
			this.totalCount = 0;
		}

		return this.totalCount;
	}

	public void setTotalCount(int var1) {
		this.totalCount = var1;
	}

	public Integer getTotalPages() {
		if (this.totalCount == -1) {
			return Integer.valueOf(-1);
		} else {
			int var1 = this.totalCount / this.pageSize;
			if (this.totalCount % this.pageSize > 0) {
				++var1;
			}

			return new Integer(var1);
		}
	}

	public boolean isHasNext() {
		return this.pageNo + 1 <= this.getTotalPages().intValue();
	}

	public int getNextPage() {
		return this.isHasNext() ? this.pageNo + 1 : this.pageNo;
	}

	public boolean isHasPre() {
		return this.pageNo - 1 >= 1;
	}

	public int getPrePage() {
		return this.isHasPre() ? this.pageNo - 1 : this.pageNo;
	}

	public String toString() {
		return "totalCount=" + this.totalCount + ",pageSize=" + this.pageSize + ",pageNo=" + this.pageNo;
	}

}
